<template>
  <div class="doctor-detail-handle">
    <div v-if="doctorData" class="detail-content">
      <el-descriptions :column="2" border>
        <!-- 基础信息 -->
        <el-descriptions-item label="工号">
          {{ doctorData.doctorNo }}
        </el-descriptions-item>
        <el-descriptions-item label="姓名">
          {{ doctorData.name }}
        </el-descriptions-item>
        <el-descriptions-item label="所属科室">
          {{ doctorData.departmentName }}
        </el-descriptions-item>
        <el-descriptions-item label="职称">
          <el-tag :type="getTitleTagType(doctorData.title)">
            {{ getTitleText(doctorData.title) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="性别">
          {{ getGenderText(doctorData.gender) }}
        </el-descriptions-item>
        <el-descriptions-item label="出生日期">
          {{ formatDate(doctorData.birthDate) }}
        </el-descriptions-item>
        <el-descriptions-item label="年龄">
          {{ calculateAge(doctorData.birthDate) }}岁
        </el-descriptions-item>
        <el-descriptions-item label="工作年限">
          {{ doctorData.workYears }}年
        </el-descriptions-item>
        
        <!-- 联系信息 -->
        <el-descriptions-item label="手机号">
          {{ doctorData.phone || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="邮箱">
          {{ doctorData.email || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="地址" :span="2">
          {{ doctorData.address || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="紧急联系人">
          {{ doctorData.emergencyContact || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="紧急联系电话">
          {{ doctorData.emergencyPhone || '-' }}
        </el-descriptions-item>
        
        <!-- 专业信息 -->
        <el-descriptions-item label="学历">
          {{ getEducationText(doctorData.education) }}
        </el-descriptions-item>
        <el-descriptions-item label="毕业院校">
          {{ doctorData.graduateSchool || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="执业证书号">
          {{ doctorData.licenseNumber || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="当前状态">
          <el-tag :type="getStatusTagType(doctorData.status)">
            {{ getStatusText(doctorData.status) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="创建时间">
          {{ formatDateTime(doctorData.createTime) }}
        </el-descriptions-item>
        <el-descriptions-item label="更新时间">
          {{ formatDateTime(doctorData.updateTime) }}
        </el-descriptions-item>
        
        <el-descriptions-item label="专业特长" :span="2">
          <div class="content-text">{{ doctorData.specialty || '无' }}</div>
        </el-descriptions-item>
        <el-descriptions-item label="个人简介" :span="2">
          <div class="content-text">{{ doctorData.introduction || '无' }}</div>
        </el-descriptions-item>
        <el-descriptions-item label="备注" :span="2">
          <div class="content-text">{{ doctorData.remark || '无' }}</div>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    
    <div class="dialog-footer">
      <el-button @click="handleClose">关闭</el-button>
    </div>
  </div>
</template>

<script setup>
// 定义props
const props = defineProps({
  doctorData: {
    type: Object,
    default: () => ({})
  }
})

// 定义emits
const emit = defineEmits(['close'])

// 获取性别文本
const getGenderText = (gender) => {
  const genderMap = {
    0: '未知',
    1: '男',
    2: '女'
  }
  return genderMap[gender] || '未知'
}

// 获取状态文本
const getStatusText = (status) => {
  const statusMap = {
    0: '离职',
    1: '在职',
    2: '休假'
  }
  return statusMap[status] || '未知'
}

// 获取状态标签类型
const getStatusTagType = (status) => {
  const typeMap = {
    0: 'danger',
    1: 'success',
    2: 'warning'
  }
  return typeMap[status] || 'info'
}

// 获取职称文本
const getTitleText = (title) => {
  const titleMap = {
    1: '主任医师',
    2: '副主任医师',
    3: '主治医师',
    4: '住院医师',
    5: '实习医师'
  }
  return titleMap[title] || '未知'
}

// 获取职称标签类型
const getTitleTagType = (title) => {
  const typeMap = {
    1: 'danger',   // 主任医师 - 红色
    2: 'warning',  // 副主任医师 - 橙色
    3: 'primary',  // 主治医师 - 蓝色
    4: 'success',  // 住院医师 - 绿色
    5: 'info'      // 实习医师 - 灰色
  }
  return typeMap[title] || 'info'
}

// 获取学历文本
const getEducationText = (education) => {
  const educationMap = {
    1: '博士',
    2: '硕士',
    3: '本科',
    4: '大专',
    5: '其他'
  }
  return educationMap[education] || '未知'
}

// 计算年龄
const calculateAge = (birthDate) => {
  if (!birthDate) return '-'
  const birth = new Date(birthDate)
  const today = new Date()
  let age = today.getFullYear() - birth.getFullYear()
  const monthDiff = today.getMonth() - birth.getMonth()
  
  if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
    age--
  }
  
  return age
}

// 格式化日期
const formatDate = (date) => {
  if (!date) return '-'
  return new Date(date).toLocaleDateString('zh-CN')
}

// 格式化日期时间
const formatDateTime = (dateTime) => {
  if (!dateTime) return '-'
  return new Date(dateTime).toLocaleString('zh-CN')
}

// 处理关闭
const handleClose = () => {
  emit('close')
}
</script>

<style scoped>
.doctor-detail-handle {
  padding: 20px 0;
}

.detail-content {
  padding: 20px 0;
}

.content-text {
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.dialog-footer {
  margin-top: 20px;
  text-align: right;
}

:deep(.el-descriptions__label) {
  font-weight: 600;
}

:deep(.el-descriptions__content) {
  word-break: break-all;
}
</style> 